package com.wrupple.muba.catalogs.client.widgets.fields.providers;

import java.util.List;

import com.google.gwt.cell.client.Cell;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.event.shared.EventBus;
import com.google.inject.Inject;
import com.wrupple.muba.catalogs.client.activity.process.task.CatalogInteractionState.Mode;
import com.wrupple.muba.catalogs.client.module.services.presentation.CatalogFormFieldProvider;
import com.wrupple.muba.catalogs.client.module.services.presentation.impl.JavaScriptAdapter.StringListJSOadapter;
import com.wrupple.muba.catalogs.client.widgets.fields.cells.JSOAdapterCell;
import com.wrupple.muba.catalogs.client.widgets.fields.cells.JSOAdapterCell.JSOAdapter;
import com.wrupple.muba.catalogs.client.widgets.fields.cells.MultiTextCell;
import com.wrupple.muba.catalogs.client.widgets.impl.CatalogUserInterfaceMessages;
import com.wrupple.muba.catalogs.client.widgets.impl.TextListEditor;
import com.wrupple.muba.common.shared.Process;
import com.wrupple.muba.common.shared.SequentialProcess;
import com.wrupple.muba.common.shared.State.ProcessManager;
import com.wrupple.vegetate.domain.FieldDescriptor;

public class MultiTextFieldProvider implements CatalogFormFieldProvider {

	CatalogUserInterfaceMessages msgs;
	
	@Inject
	public MultiTextFieldProvider(CatalogUserInterfaceMessages msgs) {
		super();
		this.msgs = msgs;
	}


	@Override
	public Cell<JavaScriptObject> createCell(EventBus bus, ProcessManager pm, FieldDescriptor d, Mode mode)  {
		TextListEditor wrapped = new TextListEditor();
		String name = msgs.editingMultipleSingleLineTextProcess();
		Process<List<String>, List<String>> process = SequentialProcess.wrap(wrapped,wrapped,name);
		Cell<List<String>> lista = new MultiTextCell(bus, pm, d,mode,process,name);
		JSOAdapter<List<String>> adapter = new StringListJSOadapter();
		Cell<JavaScriptObject> regreso = new JSOAdapterCell<List<String>>(lista,adapter);
		return regreso;
	}

}
